package com.itcast.trade.bulls.stock.user.controller;

import com.itcast.bulls.stock.common.exception.ComponentException;
import com.itcast.bulls.stock.entity.user.TradeUser;
import com.itcast.stock.common.web.vo.ApiRespResult;
import com.itcast.trade.bulls.stock.user.service.IStockUserService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>Description: </p>
 *
 * @author
 * @version 1.0
 * <p>Copyright:Copyright(c)2020</p>
 * @date
 */
@RestController()
@RequestMapping("/user")
@Log4j2
public class StockUserController extends BaseController {
    
    @Autowired
    private IStockUserService stockUserService;
    
    /**
     * 用户登陆接口
     *
     * @param userNo
     * @param userPwd
     * @return
     */
    @RequestMapping("/userLogin")
    public ApiRespResult userLogin(@RequestParam("userNo") String userNo,
                                   @RequestParam("userPwd") String userPwd) {
        
        ApiRespResult result = null;
        try {
            // 用户登陆逻辑处理
            TradeUser tradeUser = stockUserService.userLogin(userNo, userPwd);
            result = ApiRespResult.success(tradeUser);
        } catch (ComponentException e) {
            log.error(e.getMessage(), e);
            result = ApiRespResult.error(e.geterrorCodeEnum());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result = ApiRespResult.sysError(e.getMessage());
        }
        
        return result;
        
    }
    
    /**
     * 获取用户增强信息
     *
     * @param userNo
     * @param userPwd
     * @return
     */
    @RequestMapping("/getUserEnhancer")
    public ApiRespResult getUserEnhancer() {
        
        ApiRespResult result = null;
        try {
            // 获取用户增强信息
            Map<String, Object> userAdditionalInfos = getUserAdditionalInfos();
            result = ApiRespResult.success(userAdditionalInfos);
        } catch (ComponentException e) {
            log.error(e.getMessage(), e);
            result = ApiRespResult.error(e.geterrorCodeEnum());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result = ApiRespResult.sysError(e.getMessage());
        }
        
        return result;
        
    }
    
}
